package April._23.work2;

public class Main {
    private static final Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                synchronized (object) {
                    for (int i = 1; i < 8; i++) {
                        System.out.println(i);
                        object.notifyAll();
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (object) {
                    for (int i = 0; i < 8; i++) {
                        System.out.println((char) (i + 'A'));
                        object.notifyAll();
                        try {
                            object.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }

        });
        t1.start();
        Thread.sleep(100);
        t2.start();
    }
}
